﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace XUtliPoolLib
{
	// Token: 0x020001AC RID: 428
	public class XFxMgr : XSingleton<XFxMgr>
	{
		// Token: 0x06000965 RID: 2405 RVA: 0x00030E90 File Offset: 0x0002F090
		public XFxMgr()
		{
			this._innerDestroyFxCb = new XTimerMgr.ElapsedEventHandler(this.InnerDestroyFx);
		}

		// Token: 0x06000966 RID: 2406 RVA: 0x00030EC8 File Offset: 0x0002F0C8
		public XFx CreateFx(string prefab_location, LoadCallBack loadFinish = null, bool async = true)
		{
			XFx xfx = XFx.CreateXFx(prefab_location, loadFinish, async);
			this._fxs.Add(xfx._instanceID, xfx);
			return xfx;
		}

		// Token: 0x06000967 RID: 2407 RVA: 0x00030EF8 File Offset: 0x0002F0F8
		public XFx CreateAndPlay(string location, XGameObject parent, Vector3 offset, Vector3 scale, float speed_ratio = 1f, bool follow = false, float duration = -1f, bool async = true)
		{
			XFx xfx = this.CreateFx(location, null, async);
			xfx.Play(parent, offset, scale, speed_ratio, follow, false, "", 0f);
			xfx.DelayDestroy = duration;
			XSingleton<XFxMgr>.singleton.DestroyFx(xfx, false);
			return xfx;
		}

		// Token: 0x06000968 RID: 2408 RVA: 0x00030F48 File Offset: 0x0002F148
		public XFx CreateAndPlay(string location, Transform parent, Vector3 offset, Vector3 scale, float speed_ratio = 1f, bool follow = false, float duration = -1f, bool async = true)
		{
			XFx xfx = this.CreateFx(location, null, async);
			xfx.Play(parent, offset, scale, speed_ratio, follow, false);
			xfx.DelayDestroy = duration;
			XSingleton<XFxMgr>.singleton.DestroyFx(xfx, false);
			return xfx;
		}

		// Token: 0x06000969 RID: 2409 RVA: 0x00030F8C File Offset: 0x0002F18C
		public XFx CreateUIFx(string location, Transform parent, bool processMesh = false)
		{
			return this.CreateUIFx(location, parent, Vector3.one, processMesh);
		}

		// Token: 0x0600096A RID: 2410 RVA: 0x00030FAC File Offset: 0x0002F1AC
		public XFx CreateUIFx(string location, Transform parent, Vector3 scale, bool processMesh = false)
		{
			XFx xfx = this.CreateFx(location, processMesh ? XFx._ProcessMesh : null, true);
			int renderLayer = LayerMask.NameToLayer("UI");
			xfx.SetRenderLayer(renderLayer);
			xfx.Play(parent, Vector3.zero, scale, 1f, true, false);
			xfx.RefreshUIRenderQueue();
			return xfx;
		}

		// Token: 0x0600096B RID: 2411 RVA: 0x00031004 File Offset: 0x0002F204
		public void DestroyFx(XFx fx, bool bImmediately = true)
		{
            XSingleton<XTimerMgr>.singleton.KillTimer(fx.Token);
            if (bImmediately || fx.DelayDestroy <= 0f)
			{
				this.InnerDestroyFx(fx);
			}
			else
			{
				fx.Token = XSingleton<XTimerMgr>.singleton.SetTimer(fx.DelayDestroy, this._innerDestroyFxCb, fx);
			}
		}

		// Token: 0x0600096C RID: 2412 RVA: 0x00031068 File Offset: 0x0002F268
		public void OnLeaveScene()
		{
			this.Clear();
		}

		// Token: 0x0600096D RID: 2413 RVA: 0x00031068 File Offset: 0x0002F268
		public void OnLeaveStage()
		{
			this.Clear();
		}

		// Token: 0x0600096E RID: 2414 RVA: 0x00031074 File Offset: 0x0002F274
		public void PostUpdate()
		{
			foreach (KeyValuePair<int, XFx> keyValuePair in this._fxs)
			{
				XFx value = keyValuePair.Value;
				if (value != null)
				{
					value.StickToGround();
				}
			}
		}

		// Token: 0x0600096F RID: 2415 RVA: 0x000310C0 File Offset: 0x0002F2C0
		private void InnerDestroyFx(object o)
		{
			XFx xfx = o as XFx;
			if (xfx == null)
			{
				XSingleton<XDebug>.singleton.AddErrorLog("Destroy Fx error: ", o.ToString(), null, null, null, null);
			}
			else
			{
				this._fxs.Remove(xfx._instanceID);
				XFx.DestroyXFx(xfx, true);
			}
		}

		// Token: 0x06000970 RID: 2416 RVA: 0x00031114 File Offset: 0x0002F314
		public void Clear()
		{
			foreach (KeyValuePair<int, XFx> keyValuePair in this._fxs)
			{
				XFx.DestroyXFx(keyValuePair.Value, false);
			}
			this._fxs.Clear();
		}

		// Token: 0x0400042B RID: 1067
		private Dictionary<int, XFx> _fxs = new Dictionary<int, XFx>();

		// Token: 0x0400042C RID: 1068
		private XTimerMgr.ElapsedEventHandler _innerDestroyFxCb = null;

		// Token: 0x0400042D RID: 1069
		public int CameraLayerMask = -1;

		// Token: 0x0400042E RID: 1070
		public static bool EmptyFx = false;

		// Token: 0x0400042F RID: 1071
		public static bool FilterFarFx = false;

		// Token: 0x04000430 RID: 1072
		public static float FilterFxDis0 = 200f;

		// Token: 0x04000431 RID: 1073
		public static float FilterFxDis1 = 300f;

		// Token: 0x04000432 RID: 1074
		public static float FilterFxDis2 = 500f;

		// Token: 0x04000433 RID: 1075
		public static float FilterFxDis4 = 1600f;

		// Token: 0x04000434 RID: 1076
		public static int maxBehitFx = 3;

		// Token: 0x04000435 RID: 1077
		public static int currentBeHitFx = 0;

		// Token: 0x04000436 RID: 1078
		public static float minBehitFxTime = 0.1f;

		// Token: 0x04000437 RID: 1079
		public static float lastBehitFxTime = 0f;

		// Token: 0x04000438 RID: 1080
		public static int MaxParticelCount = -1;
	}
}
